package cn.jsu.oj.dispatchServer.satellite.heart;

import cn.jsu.oj.dispatchServer.satellite.netty.starter.SatelliteStarter;
import cn.jsu.oj.dispatchServer.satellite.server.SatelliteServer;
import cn.jsu.oj.dispatchServer.satellite.util.SpringUtil;
import org.quartz.Job;
import org.quartz.JobExecutionContext;

/**
 * 客户端心跳超时工作
 *
 * @author shan
 * @date 2022/07/09
 */
public class HeartClientTimeoutJob implements Job {
    
    SatelliteServer satelliteServer;
    
    HeartClientService heartClientService;

    public HeartClientTimeoutJob() {
        satelliteServer = (SatelliteServer) SpringUtil.getBean("satelliteServer");
        heartClientService = (HeartClientService) SpringUtil.getBean("heartClientService");
    }

    @Override
    public void execute(JobExecutionContext jobExecutionContext) {
        if (heartClientService.getResponse()) {
            heartClientService.setResponse(false);
            return;
        }
        if (satelliteServer.getChannel() != null) {
            satelliteServer.getChannel().close();
        }
        SatelliteStarter.activeSign = false;
        SatelliteStarter.verifySign = false;
    }
}
